package com.jr.service.impl;

import com.jr.dao.OrderDao;
import com.jr.dao.impl.OrderDaoImpl;
import com.jr.entity.Order;
import com.jr.service.OrderService;

import java.util.List;

public class OrderServiceImpl implements OrderService {
    private OrderDao orderDao = new OrderDaoImpl();
    @Override
    public List<Order> selectAllOrder(Integer enterpriseId) throws Exception {
        return orderDao.listAllOrder(enterpriseId);
    }

    @Override
    public long getOrderTotal(Integer enterpriseId) throws Exception {
        return orderDao.getTotal(enterpriseId);
    }

    @Override
    public List<Order> listOrder(Integer enterpriseId, int start, int pageSize) throws Exception {
        return orderDao.findOrder(enterpriseId,start,pageSize);
    }

    @Override
    public int delete(String no) throws Exception {
        return orderDao.deleteOrder(no);
    }

    /**
     * 根据发票id查询所有相关订单
     * @param invoiceId
     * @return
     * @throws Exception
     */
    @Override
    public List<Order> invoiceOrder(Integer invoiceId) throws Exception {
        return orderDao.invoiceOrder(invoiceId);
    }

    /**
     * 根据发票id计算开票总金额
     * @param invoiceId
     * @return
     * @throws Exception
     */
    @Override
    public Double TotalAmount(Integer invoiceId) throws Exception {
        return orderDao.TotalAmount(invoiceId);
    }

    /**
     * 订单总金额
     * @return
     * @throws Exception
     */
    @Override
    public Double sumAmount() throws Exception {
        return orderDao.sumAmount();
    }

    /**
     * 根据开票状态计算已经开票的总金额
     * @return
     * @throws Exception
     */
    @Override
    public Double finishSumAmount() throws Exception {
        return orderDao.finishSumAmount();
    }

    @Override
    public int update(String no) throws Exception {
        return orderDao.updateOrder(no);
    }

    @Override
    public int updateStatus(String no) throws Exception {
        return orderDao.updateStatus(no);
    }

    /**
     * 根据发票id进行退票
     * @param invoiceId
     * @return
     * @throws Exception
     */
    @Override
    public int refundTicket(Integer invoiceId) throws Exception {
        return orderDao.refundTicket(invoiceId);
    }
}
